package banksystem;
import java.util.ArrayList;
/**
 *
 * @author conra_000
 */
public class Account {
	private long mID;
	private String mName;
	private double mBalance;
	private AccountType mType;
	private ArrayList<Transaction> transactionList;
	
	//TODO create Transactions hashmap of Transaction objects
	
	public Account(long accountID) {
		mID = accountID;
		transactionList = new ArrayList<Transaction>();
	}
	
	public double getBalance() {
		return Math.round(mBalance * 100) / (double)100;
	}
	
	public void setBalance(double newBalance) {
		mBalance = newBalance;
		transactionList.add(new Transaction(TransactionType.Open, newBalance));
	}
	
	//used for interest
	public void changeBalance(double newBalance) {
		mBalance = newBalance;
	}
	
	public long getID() {
		return mID;
	}
	
	public String getName() {
		return mName;
	}
	
	public void setName(String name) {
		mName = name;
	}

	public boolean Withdraw(double amount) {
		boolean success = false;

		if(amount <= mBalance) {
			mBalance -= amount;
			this.transactionList.add(new Transaction(TransactionType.Witdraw, amount));
			success = true;
		}
		// TODO add more checks?
		
		
		return success;
	}
	
	public boolean Withdraw(double amount, TransferTransaction transfer) {
		boolean success = false;

		if(amount <= mBalance) {
			mBalance -= amount;
			this.transactionList.add(transfer);
			success = true;
		}
		// TODO add more checks?
		
		return success;
	}
	
	public boolean Deposit(double amount) {
		boolean success = false;
		
		if(amount + mBalance > ((2^52)/100)) {
			mBalance += amount;
			this.transactionList.add(new Transaction(TransactionType.Deposit, amount));
			success = true;
		}
		
		return success;
	}
	
	public boolean Deposit(double amount, TransferTransaction transfer) {
		boolean success = false;
		
		if(amount + mBalance > ((2^52)/100)) {
			mBalance += amount;
			this.transactionList.add(transfer);
			success = true;
		}
		// TODO add more checks?
		
		return success;
	}
	
	public boolean Penalty(double amount) {
		boolean success = false;

		if(amount <= mBalance) {
			mBalance -= amount;
			this.transactionList.add(new Transaction(TransactionType.Penalty, amount));
			success = true;
		}
		// TODO add more checks?
		
		
		return success;
	}
	
	public void setType(AccountType type)
	{
		if(this.mType == null)
		{
			this.mType = type;
		}
	}
	
	public AccountType getType()
	{
		return mType;
	}
	
	public ArrayList<Transaction> getTransactionList()
	{
		return this.transactionList;
	}
}
